/**
 * Created by yinhong on 2018/7/7.
 */
//雷达数据
var data1 = {
    "type": "1",
    "name": ["济南NMC",'济南二',"滨州NMC","华北NMC","华北二"],
    "dataArry": [
		"http://www.nmc.cn/publish/radar/shan-dong/ji-nan.htm",
        "http://products.weather.com.cn/product/radar/index/procode/JC_RADAR_AZ9531_JB",
        "http://www.nmc.cn/publish/radar/shan-dong/bin-zhou.htm",
        "http://www.nmc.cn/publish/radar/huabei.html",
        "http://www.weather.com.cn/radar/hb.shtml",
    ]
};

//云图数据
var data2 = {
    "type": "1",
    "name": ["云图一","葵花高清","高清二"],
    "dataArry": [
        "http://www.nmc.cn/publish/satellite/fy2.htm",
		"http://www.weather.com.cn/satellite",
        "https://www.cwb.gov.tw/V8/C/W/OBS_Sat.html",
    ]
};

//数值数据
// var data3 = {
//     "type": "1",
//     "firstnav": "天气形势",
//     "name": [
// 		"地面分析","200hpa高空","500hpa高空","700hpa高空","850hpa高空"],
// 		"dataArry": ["http://www.gdmo.cn/weather-gdmo/data/img/dmfx/chartsur.GIF",
// 		"http://www.gdmo.cn/weather-gdmo/data/img/gkxs_200/chart200.GIF",
// 		"http://www.gdmo.cn/weather-gdmo/data/img/gkxs_500/chart500.GIF",
// 		"http://www.gdmo.cn/weather-gdmo/data/img/gkxs_700/chart700.GIF",
// 		"http://www.gdmo.cn/weather-gdmo/data/img/gkxs_850/chart850.GIF",
// 	]
// };

var data4 = {
    "type": "1",
    "firstnav": "",
    "name": ["未来24小时","未来48小时","实况天气"],
    "dataArry": [
		"http://www.jma.go.jp/jp/g3/images/jp_c/24h/",
		"http://www.jma.go.jp/jp/g3/images/jp_c/48h/",
		"http://www.jma.go.jp/jp/g3/images/jp_c/",
		]
};

var str;
navClick(data1,'itemWrapLeida');
function navClick(data,subNavId){
    $('#'+subNavId).empty();
    $.each(data.name,function(i,ele){
        str = '<li class="item" dataSrc="'+data.dataArry[i]+'">'+ele+'</li>';
        $('#'+subNavId).append(str);
    });
    $('#'+subNavId).children().eq(0).addClass('itemActive');
    $('#'+subNavId).children().eq(0).click();
}
//一级导航切换
$('#nav .navList').eq(0).on('click',function(){
    $(this).addClass('navActive').siblings().removeClass('navActive');
    $('.con .content').eq(0).addClass('conActive').siblings().removeClass('conActive');
    navClick(data1,'itemWrapLeida');

});
$('#nav .navList').eq(1).on('click',function(){
    $(this).addClass('navActive').siblings().removeClass('navActive');
    $('.con .content').eq(1).addClass('conActive').siblings().removeClass('conActive');
    navClick(data2,'itemWrapCloud');
});
$('#nav .navList').eq(2).on('click',function(){
    $(this).addClass('navActive').siblings().removeClass('navActive');
    $('.con .content').eq(2).addClass('conActive').siblings().removeClass('conActive');
    $('#firsNav .item').eq(0).html(data4.firstnav);
    navClick(data4,'itemWrapShuzhi');
});

//数值
// $('#firsNav .item').eq(0).click(function(){
//     $(this).addClass('itemActive').siblings().removeClass('itemActive');
//     navClick(data3,'itemWrapShuzhi');
// });
$('#firsNav .item').eq(0).click(function(){
    $(this).addClass('itemActive');
    navClick(data4,'itemWrapShuzhi');
});

//雷达导航切换
$('#itemWrapLeida').on('click','.item',function(){
    $(this).addClass('itemActive').siblings().removeClass('itemActive');
    if($(this).html() == "济南二" || $(this).html() == "华北二"){
        $('#wrapperLeida').addClass('maskTwo');
        $('#wrapperLeida').removeClass('maskNone');
    }else if($(this).html() == "滨州NMC" ||$(this).html() == "华北NMC"||$(this).html() == "济南二"){
        $('#wrapperLeida').addClass('maskNone');
        $('#wrapperLeida').removeClass('maskTwo');
    }else{
        $('#wrapperLeida').removeClass('maskNone');
        $('#wrapperLeida').removeClass('maskTwo');
    }
    $('#iframePageLeida').attr('src',$(this).attr('dataSrc'));
});
//云图导航切换
$('#itemWrapCloud').on('click','.item',function(){
    $(this).addClass('itemActive').siblings().removeClass('itemActive');
    if($(this).html() == "云图一"){
        $('#wrapperCloud').addClass('maskTwo');
        $('#wrapperCloud').removeClass('maskThree');
        $('#wrapperCloud').removeClass('maskFour');
    }else if($(this).html() == "云图二"){
        $('#wrapperCloud').addClass('maskThree');
        $('#wrapperCloud').removeClass('maskTwo');
        $('#wrapperCloud').removeClass('maskFour');
    }else if($(this).html() == "高清二"){
        $('#wrapperCloud').addClass('maskFour');
        $('#wrapperCloud').removeClass('maskTwo');
        $('#wrapperCloud').removeClass('maskThree');
    }
    $('#iframePageCloud').attr('src',$(this).attr('dataSrc'));
});

//数据导航切换
$('#itemWrapShuzhi').on('click','.item',function(){
		$(this).addClass('itemActive').siblings().removeClass('itemActive');
    
        //获取当前年 月 日 小时 （日本时间）
        var date = new Date();
        var today = GetDateStr(0);     //今天日期
        var tomorrow = GetDateStr(0); //明天日期 2018-7-9
        var aftertomorrow = GetDateStr(1); //后天
        //今天年月日小时
        var year = today.split('-')[0].slice(2);
        var month = today.split('-')[1];
        var day = today.split('-')[2];
        var hour = (date.getHours())%24; //日本天气+1 小时
        //如果是 实况天气图
        if($(this).html() == data4.name[2]){
            $('#iframePageShuzhi2').hide();
			//规律是0 3 6 9 12 15 18 21
            hour = hour - hour%3-3;
            if(hour == 0 || hour == 3 ){
                hour = 21;
            }
			console.log(hour)
            var strTime = year + getzf(month) + getzf(day) + getzf(hour).toString();
            var src = $(this).attr('dataSrc') + strTime + '.png';
            $('#iframePageShuzhi').attr('src',src);
        }else{   //否则是未来24 48小时图
            $('#iframePageShuzhi2').show();
            hour = getzf(hour - hour%3);
            var hour2;
            if(hour>=9&&hour<=21 ){
                hour = 9;
                hour2 = 21;
            }else{
                hour = 21;
                hour2 = 9;
            }
            if($(this).html() == data4.name[0]){  //如果当前是未来24小时
                year = tomorrow.split('-')[0].slice(2);
                month = tomorrow.split('-')[1];
                day = tomorrow.split('-')[2];
            }else if($(this).html() == data4.name[1]){ //如果当前是未来48小时
                year = aftertomorrow.split('-')[0].slice(2);
                month = aftertomorrow.split('-')[1];
                day = aftertomorrow.split('-')[2];
            }
            var strTime = year + getzf(month) + getzf(day) + getzf(hour);
            var strTime2 = year + getzf(month) + getzf(day) + getzf(hour2)
            var src = $(this).attr('dataSrc') + strTime + '.png';
            var src2 =  $(this).attr('dataSrc') + strTime2 + '.png';
            $('#iframePageShuzhi').attr('src',src);
            $('#iframePageShuzhi2').attr('src',src2);
        }
});

function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return y+"-"+m+"-"+d;
}